<?php

class CCoreBaseIoStream
{
	private $_rResourse;

	public function __construct()
	{
		$this->_rResourse = null;
	}

	public function __destruct()
	{
		$this->Close();
	}

	function Close()
	{
		if (is_resource($this->_rResourse))
		{
			@fclose($this->_rResourse);
		}
		$this->_rResourse = null;
	}

	function GetHandle()
	{
		return $this->_rResourse;
	}

	public function InitByString($sData)
	{
		if (($this->_rResourse = @fopen('php://memory', 'w+b')) === false)
		{
			return false;
		}

		if (strlen($sData) > 0 && (false === @fwrite($this->_rResourse, $sData)))
		{
			return false;
		}

		@fseek($this->_rResourse, 0);
	}

	public function InitByFile($sFilePath)
	{
		if (($this->_rResourse = @fopen($sFilePath, 'r+b')) === false)
		{
			return false;
		}

		@fseek($this->_rResourse, 0);
	}

	public function InitByHandle($rResourse)
	{
		$this->_rResourse = $rResourse;
		@fseek($this->_rResourse, 0);
	}
}